using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VFZUTEIL
    {
        public DataRow Convert2FZUTEIL(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryFZUTEIL(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["FZMANDANT"] = " ".PadRight(2 ); 
         dwReturn["FZAUFTYP"] = " ".PadRight(1 ); 
         dwReturn["FZAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["FZAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["FZAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["FZTEILNR"] = " ".PadRight(4 ); 
         dwReturn["FZART"] = " ".PadRight(20 ); 
         dwReturn["FZVAR"] = " ".PadRight(2 ); 
         dwReturn["FZFARBE"] = " ".PadRight(10 ); 
         dwReturn["FZGROE"] = " ".PadRight(7 ); 
         dwReturn["FZAUFM"] = " ".PadRight(2 ); 
         dwReturn["FZVPEINH"] = " ".PadRight(3 ); 
         dwReturn["FZANZVP"] = " ".PadRight(0 ); 
         dwReturn["FZZS"] = " ".PadRight(2 ); 
         dwReturn["FZCHAR"] = " ".PadRight(0 ); 
         dwReturn["FZGNR"] = " ".PadRight(0 ); 
         dwReturn["FZGNRPOS"] = " ".PadRight(0 ); 
         dwReturn["FZLO"] = " ".PadRight(2 ); 
         dwReturn["FZLB"] = " ".PadRight(2 ); 
         dwReturn["FZLP"] = " ".PadRight(8 ); 
         dwReturn["FZME"] = " ".PadRight(0 ); 
         dwReturn["FZAUFBKZ"] = " ".PadRight(1 ); 
         dwReturn["FZCHARL"] = " ".PadRight(15 ); 
         dwReturn["FZCHARLZUS"] = " ".PadRight(15 ); 
         dwReturn["FZSETPOS"] = " ".PadRight(0 ); 
         dwReturn["FZSETANZ"] = " ".PadRight(0 ); 
         dwReturn["FZFILLER"] = " ".PadRight(23 ); 
         dwReturn["FZAENDZL"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapFZUTEIL(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveFZUTEIL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryFZUTEIL(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapFZUTEIL(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertFZUTEIL(dwLocal, ITXDBVERSION);
            }
            UpdateFZUTEIL(dwLocal);
        }
        public void InsertFZUTEIL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO FZUTEIL(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryFZUTEIL(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM FZUTEIL WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM FZUTEIL  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "FZUTEIL";
            Return = Result;
            return Return;
        }
        public void DeleteFZUTEIL(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM FZUTEIL   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateFZUTEIL(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE FZUTEIL SET "
                    +"FZMANDANT= :FZMANDANT,"
                    +"FZAUFTYP= :FZAUFTYP,"
                    +"FZAUFKRS= :FZAUFKRS,"
                    +"FZAUFLFD= :FZAUFLFD,"
                    +"FZAUFPOS= :FZAUFPOS,"
                    +"FZTEILNR= :FZTEILNR,"
                    +"FZART= :FZART,"
                    +"FZVAR= :FZVAR,"
                    +"FZFARBE= :FZFARBE,"
                    +"FZGROE= :FZGROE,"
                    +"FZAUFM= :FZAUFM,"
                    +"FZVPEINH= :FZVPEINH,"
                    +"FZANZVP= :FZANZVP,"
                    +"FZZS= :FZZS,"
                    +"FZCHAR= :FZCHAR,"
                    +"FZGNR= :FZGNR,"
                    +"FZGNRPOS= :FZGNRPOS,"
                    +"FZLO= :FZLO,"
                    +"FZLB= :FZLB,"
                    +"FZLP= :FZLP,"
                    +"FZME= :FZME,"
                    +"FZAUFBKZ= :FZAUFBKZ,"
                    +"FZCHARL= :FZCHARL,"
                    +"FZCHARLZUS= :FZCHARLZUS,"
                    +"FZSETPOS= :FZSETPOS,"
                    +"FZSETANZ= :FZSETANZ,"
                    +"FZFILLER= :FZFILLER,"
                    +"FZAENDZL= :FZAENDZL,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("FZMANDANT", OracleType.NVarChar).Value = dwData["FZMANDANT"].ToString(); 
          or1.Parameters.Add("FZAUFTYP", OracleType.NVarChar).Value = dwData["FZAUFTYP"].ToString(); 
          or1.Parameters.Add("FZAUFKRS", OracleType.NVarChar).Value = dwData["FZAUFKRS"].ToString(); 
          or1.Parameters.Add("FZAUFLFD", OracleType.NVarChar).Value = dwData["FZAUFLFD"].ToString(); 
          or1.Parameters.Add("FZAUFPOS", OracleType.NVarChar).Value = dwData["FZAUFPOS"].ToString(); 
          or1.Parameters.Add("FZTEILNR", OracleType.NVarChar).Value = dwData["FZTEILNR"].ToString(); 
          or1.Parameters.Add("FZART", OracleType.NVarChar).Value = dwData["FZART"].ToString(); 
          or1.Parameters.Add("FZVAR", OracleType.NVarChar).Value = dwData["FZVAR"].ToString(); 
          or1.Parameters.Add("FZFARBE", OracleType.NVarChar).Value = dwData["FZFARBE"].ToString(); 
          or1.Parameters.Add("FZGROE", OracleType.NVarChar).Value = dwData["FZGROE"].ToString(); 
          or1.Parameters.Add("FZAUFM", OracleType.NVarChar).Value = dwData["FZAUFM"].ToString(); 
          or1.Parameters.Add("FZVPEINH", OracleType.NVarChar).Value = dwData["FZVPEINH"].ToString(); 
          or1.Parameters.Add("FZANZVP", OracleType.NVarChar).Value = dwData["FZANZVP"].ToString(); 
          or1.Parameters.Add("FZZS", OracleType.NVarChar).Value = dwData["FZZS"].ToString(); 
          or1.Parameters.Add("FZCHAR", OracleType.NVarChar).Value = dwData["FZCHAR"].ToString(); 
          or1.Parameters.Add("FZGNR", OracleType.NVarChar).Value = dwData["FZGNR"].ToString(); 
          or1.Parameters.Add("FZGNRPOS", OracleType.NVarChar).Value = dwData["FZGNRPOS"].ToString(); 
          or1.Parameters.Add("FZLO", OracleType.NVarChar).Value = dwData["FZLO"].ToString(); 
          or1.Parameters.Add("FZLB", OracleType.NVarChar).Value = dwData["FZLB"].ToString(); 
          or1.Parameters.Add("FZLP", OracleType.NVarChar).Value = dwData["FZLP"].ToString(); 
          or1.Parameters.Add("FZME", OracleType.NVarChar).Value = dwData["FZME"].ToString(); 
          or1.Parameters.Add("FZAUFBKZ", OracleType.NVarChar).Value = dwData["FZAUFBKZ"].ToString(); 
          or1.Parameters.Add("FZCHARL", OracleType.NVarChar).Value = dwData["FZCHARL"].ToString(); 
          or1.Parameters.Add("FZCHARLZUS", OracleType.NVarChar).Value = dwData["FZCHARLZUS"].ToString(); 
          or1.Parameters.Add("FZSETPOS", OracleType.NVarChar).Value = dwData["FZSETPOS"].ToString(); 
          or1.Parameters.Add("FZSETANZ", OracleType.NVarChar).Value = dwData["FZSETANZ"].ToString(); 
          or1.Parameters.Add("FZFILLER", OracleType.NVarChar).Value = dwData["FZFILLER"].ToString(); 
          or1.Parameters.Add("FZAENDZL", OracleType.NVarChar).Value = dwData["FZAENDZL"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
